(ns kudryashov.projecteuler.p4.p4-bruteforce)

(def tens (iterate #(* 10 %) 1))

(defn digits [x digs]
  (cond
    (< x 1) digs
    (< x 10) (digits (/ x 10) (conj digs (int x)))
    :else (digits (Math/floor (/ x 10)) (conj digs (rem (int x) 10)))))

(defn palind? [x]
  (let [digs (digits x '())]
    (= digs (reverse digs))))

(def naturals (iterate inc 1))

(defn naturals-from [x] (drop (dec x) naturals))

(defn naturals-range [from to]
  (take-while #(<= % to) (naturals-from from)))

(def r (naturals-range 100 999))

(def products (reverse (sort (for [x r y (naturals-range x 999)] (* x y)))))
; (def products (reverse (sort (for [x r y r] (* x y)))))

(println (time (first (filter palind? products))))